//Sorting algorythm - QuickSort
#include <string>
#include <iostream>
using namespace std;

void Qsort(int arr[], int arrBegin, int arrEnd) 
{
	int indexBegin	= arrBegin;	//left index from which we start looking from
	int indexEnd	= arrEnd;	//right index from which we start looking from

	int middleElement = arr[(arrEnd + arrBegin) / 2];//middle element of array
	
	while (indexBegin <= indexEnd) 
	{
		while (arr[indexBegin] < middleElement)
			indexBegin++;//looking through left part
		
		while (arr[indexEnd] > middleElement)
			indexEnd--;//looking through right part
		
		if (indexBegin <= indexEnd) 
		{
			if(indexBegin<indexEnd) swap(arr[indexBegin],arr[indexEnd]);//change elements if they are not in their places
			indexBegin++;//going to other elements
			indexEnd--;
		}
	
	};
	
	if (arrBegin < indexEnd)
		Qsort(arr, arrBegin, indexEnd);//started sort for part of array
	if (indexBegin < arrEnd)
		Qsort(arr, indexBegin, arrEnd);//started sort for part of array
}

int main()
{
	int i;
	int a[100];//array to sort
	
	for (i = 0; i < 100; i++)
		a[i] = (int)(rand() / (double) 32767 * 100);//infill of array

	Qsort(a, 0, 99);//sort

	for (i = 0; i < 100; i++)
		printf("%d ", a[i]);//print array
	
	getchar();
}	